#include <iostream>
#include <string>
#include "user.pb.h"
#include "mprpcappliaction.h"
#include "rpcprovider.h"
#include "logger.h"

class UserService : public fixbug::UserServiceRpc
{
private:
    /* data */
public:
    bool Login(std::string username, std::string password)
    {
        std::cout << "username: " << username << std::endl;
        std::cout << "password: " << password << std::endl;
        return true;
    }
    // 重写远程callee的虚函数
    void Login(::google::protobuf::RpcController *controller,
               const ::fixbug::LoginRequest *request,
               ::fixbug::LoginResponse *response,
               ::google::protobuf::Closure *done)
    {
        // 服务器登陆实现
        bool result = Login(request->name(), request->pwd());

        // 构造返回的response对象
        fixbug::ResultCode *login_code = response->mutable_result();
        login_code->set_errcode(0);
        login_code->set_errmsg("");
        response->set_success(result);

        // 将response序列化后通过网络发送回请求方
        done->Run();
    }
};

int main(int argc, char **argv)
{
    MprpcApplication::Init(argc, argv);

    RpcProvider provider;
    provider.NotifyService(new UserService());

    provider.Run();

    return 0;
}